#include "cppTutorOverloadingBinaryOperator.h"

#include <iostream>

CcppTutorOverloadingBinaryOperator :: CcppTutorOverloadingBinaryOperator ()
{
    m_nValueA = 0;
    m_nValueB = 0;
}

CcppTutorOverloadingBinaryOperator :: CcppTutorOverloadingBinaryOperator (int nValueA, int nValueB, bool bValueA, bool bValueB) : m_nValueA (nValueA), m_nValueB (nValueB), m_bValueA (bValueA), m_bValueB (bValueB)
{
    m_npValue = NULL;
    m_npValue = &m_nValueA;
}

CcppTutorOverloadingBinaryOperator :: ~CcppTutorOverloadingBinaryOperator ()
{
}

void CcppTutorOverloadingBinaryOperator :: m_DisplayValue ()
{
    cout << "m_nValueA = " << m_nValueA << endl;
    cout << "m_nValueB = " << m_nValueB << endl;

    if (m_bValueA)
        cout << "m_bValueA = true" << endl;
    else
        cout << "m_bValueA = false" << endl;

    if (m_bValueB)
        cout << "m_bValueB = true" << endl;
    else
        cout << "m_bValueB = false" << endl;
}

#ifdef OPERATOR_OVERLOADING
    #ifdef BINARY_OVERLOADING_OPERATOR_USING_FRIEND
    CcppTutorOverloadingBinaryOperator operator + (const CcppTutorOverloadingBinaryOperator& obo1, 
                                                    const CcppTutorOverloadingBinaryOperator& obo2)
    {
        return CcppTutorOverloadingBinaryOperator ((obo1.m_nValueA + obo2.m_nValueA),
                                                   (obo1.m_nValueB + obo2.m_nValueB),
                                                   (obo1.m_bValueA + obo2.m_bValueA),
                                                   (obo1.m_bValueB + obo2.m_bValueB));
    }

    CcppTutorOverloadingBinaryOperator operator - (const CcppTutorOverloadingBinaryOperator& obo1, 
                                                   const CcppTutorOverloadingBinaryOperator& obo2)
    {
        return CcppTutorOverloadingBinaryOperator ((obo1.m_nValueA - obo2.m_nValueA),
                                                   (obo1.m_nValueB - obo2.m_nValueB),
                                                   (obo1.m_bValueA - obo2.m_bValueA),
                                                   (obo1.m_bValueB - obo2.m_bValueB));
    }
    #else
    CcppTutorOverloadingBinaryOperator& CcppTutorOverloadingBinaryOperator :: operator + (const CcppTutorOverloadingBinaryOperator& obo1)
    {
        CcppTutorOverloadingBinaryOperator oboTemp;

        oboTemp.m_nValueA = this->m_nValueA + obo1.m_nValueA;
        oboTemp.m_nValueB = this->m_nValueB + obo1.m_nValueB;

        return oboTemp;
    }

    CcppTutorOverloadingBinaryOperator& CcppTutorOverloadingBinaryOperator :: operator - (const CcppTutorOverloadingBinaryOperator& obo1)
    {
        CcppTutorOverloadingBinaryOperator oboTemp;

        oboTemp.m_nValueA = this->m_nValueA - obo1.m_nValueA;
        oboTemp.m_nValueB = this->m_nValueB - obo1.m_nValueB;

        return oboTemp;
    }

    CcppTutorOverloadingBinaryOperator& CcppTutorOverloadingBinaryOperator :: operator * (const CcppTutorOverloadingBinaryOperator& obo1)
    {
        CcppTutorOverloadingBinaryOperator oboTemp;

        oboTemp.m_nValueA = this->m_nValueA * obo1.m_nValueA;
        oboTemp.m_nValueB = this->m_nValueB * obo1.m_nValueB;

        return oboTemp;
    }

    CcppTutorOverloadingBinaryOperator& CcppTutorOverloadingBinaryOperator :: operator / (const CcppTutorOverloadingBinaryOperator& obo1)
    {
        CcppTutorOverloadingBinaryOperator oboTemp;

        oboTemp.m_nValueA = (this->m_nValueA / obo1.m_nValueA);
        oboTemp.m_nValueB = (this->m_nValueB / obo1.m_nValueB);

        return oboTemp;
    }

    CcppTutorOverloadingBinaryOperator& CcppTutorOverloadingBinaryOperator :: operator % (const CcppTutorOverloadingBinaryOperator& obo1)
    {
        CcppTutorOverloadingBinaryOperator oboTemp;

        oboTemp.m_nValueA = (this->m_nValueA % obo1.m_nValueA);
        oboTemp.m_nValueB = (this->m_nValueB % obo1.m_nValueB);

        return oboTemp;
    }

    CcppTutorOverloadingBinaryOperator& CcppTutorOverloadingBinaryOperator :: operator ^ (const CcppTutorOverloadingBinaryOperator& obo1)
    {	
        CcppTutorOverloadingBinaryOperator oboTemp;

        oboTemp.m_nValueA = (this->m_nValueA ^ obo1.m_nValueA);
        oboTemp.m_nValueB = (this->m_nValueB ^ obo1.m_nValueB);

        return oboTemp;
    }

    CcppTutorOverloadingBinaryOperator& CcppTutorOverloadingBinaryOperator :: operator & (const CcppTutorOverloadingBinaryOperator& obo1)
    {
        CcppTutorOverloadingBinaryOperator oboTemp;

        oboTemp.m_nValueA = (this->m_nValueA & obo1.m_nValueA);
        oboTemp.m_nValueB = (this->m_nValueB & obo1.m_nValueB);

        return oboTemp;
    }

    CcppTutorOverloadingBinaryOperator& CcppTutorOverloadingBinaryOperator :: operator += (const CcppTutorOverloadingBinaryOperator& obo1)
    {
        if (this == &obo1) {
            this->m_nValueA += this->m_nValueA;
            this->m_nValueB += this->m_nValueB;
            return *this;
        }

        m_nValueA += obo1.m_nValueA;
        m_nValueB += obo1.m_nValueB;

        return *this;
    }

    #endif // BINARY_OVERLOADING_OPERATOR_USING_FRIEND
#endif //OPERATOR_OVERLOADING